# 容器名称
container_name="mysql-temp"
# 数据库账户
mysql_name="root"
# 数据库密码
mysql_pwd="xxx"
# 数据库备份根目录
backup_dir="/home/backup-mysql"
# 备份数据库
backup_db="--all-databases"
# 备份数据保留天数
backup_clean_day=7
mkdir -p ${backup_dir}
mkdir -p ${backup_dir}/resource
find ${backup_dir}/resource -type f -mtime +${backup_clean_day} -delete
/usr/bin/docker exec -i ${container_name}  mysqldump -u${mysql_name} -p${mysql_pwd} ${backup_db} |  gzip > ${backup_dir}/resource/`date "+%Y_%m_%d_%H_%M_%S"`.sql.gz